<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    width="600px"
    :before-close="handleClose"
    custom-class="announcement-dialog"
    :close-on-click-modal="false"
    :show-close="false"
  >
    <div class="content-wrapper">
      <div class="scroll-container" v-html="formattedContent"></div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        @click="handleConfirm"
        class="confirm-btn"
      >
        确 定
      </el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: 'AnnouncementDialog',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    title: {
      type: String,
      default: '系统公告'
    },
    content: {
      type: String,
      default: ''
    }
  },
  computed: {
    formattedContent() {
      return (this.content || '').replace(/\n/g, '<br>')
    }
  },
  methods: {
    handleConfirm() {
      this.$emit('confirm')
    },
    handleClose() {
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped>
/* 添加动画效果 */
::v-deep .announcement-dialog {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;

  .el-dialog__header {
    padding: 20px 24px 10px;
    border-bottom: 1px solid #f0f0f0;

    .el-dialog__title {
      font-size: 18px;
      font-weight: 600;
      color: #333;
    }
  }

  .el-dialog__body {
    padding: 0;
  }

  .el-dialog__footer {
    padding: 16px 24px;
    border-top: 1px solid #f0f0f0;
  }
}

.content-wrapper {
  padding: 20px 24px;
  max-height: 60vh;
  overflow: hidden;

  .scroll-container {
    max-height: 100%;
    overflow-y: auto;
    padding-right: 8px;

    /* 自定义滚动条 */
    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-track {
      background: #f5f5f5;
      border-radius: 3px;
    }

    &::-webkit-scrollbar-thumb {
      background: #c1c1c1;
      border-radius: 3px;
      transition: background 0.3s;

      &:hover {
        background: #a8a8a8;
      }
    }
  }
}

.dialog-footer {
  text-align: center;

  .confirm-btn {
    padding: 10px 24px;
    border-radius: 6px;
    font-weight: 500;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    }

    &:active {
      transform: translateY(0);
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
  }
}

/* 淡入淡出动画 */
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}
</style>
